<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class player_model extends CI_Model {

	public function get_vdo($category_id)
	{
		$this->db->limit(20);
		$this->db->where('vdo_status' ,0);
		$this->db->where('category_id' ,$category_id);
		$this->db->where('thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$query = $this->db->get('vdo');
		return $query->result_array();
	}


	public function new_vdo()
	{
		$this->db->order_by("vdo.vdo_id", "desc");
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$query = $this->db->get('vdo',4);
		return $query->result_array();
	}

	public function view_vdo($input)
	{
		$this->db->where('vdo_id',$input['vdo_id']);
		$this->db->update('vdo',$input);
	}

	public function add_history($check_last_history)
	{
		$this->db->insert('history',$check_last_history);
	}

	public function check_last_history($mem_id)
	{
		$this->db->order_by('his_id','desc');
		$this->db->where('mem_id',$mem_id);
		$query = $this->db->get('history',1);
		return $query->result_array();
	}

	public function like($vdo_id)
	{
		$this->db->where('like_rate' ,1);
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('like');
        return count($query->result_array());
	}

	public function dislike($vdo_id)
	{
		$this->db->where('dislike_rate' ,1);
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('dislike');
    	return count($query->result_array());
	}

	public function check_liked($mem_id ,$vdo_id)
	{
		$this->db->where('mem_id' ,$mem_id);
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('like');
		return $query->result_array();
	}

	public function check_disliked($mem_id ,$vdo_id)
	{
		$this->db->where('mem_id' ,$mem_id);
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('dislike');
		return $query->result_array();
	}

	public function add_like($input)
	{
		$this->db->insert('like' ,$input);
	}

	public function update_like($like ,$like_id)
	{
		$this->db->where('like_id' ,$like_id);
		$this->db->update('like' ,$like);
	}

	public function update_dislike($dislike ,$dislike_id)
	{
		$this->db->where('dislike_id' ,$dislike_id);
		$this->db->update('dislike' ,$dislike);
	}

	public function add_dislike($input)
	{
		$this->db->insert('dislike' ,$input);
	}

	public function check_favorite($mem_id ,$vdo_id)
	{
		$this->db->where('mem_id' ,$mem_id);
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('favorite');
		return $query->result_array();
	}

	public function update_all_like($all_like)
	{
		$this->db->where('vdo_id' ,$all_like['vdo_id']);
		$this->db->update('vdo' ,$all_like);
	}

	public function get_report($vdo_id)
	{
		$this->db->select('rvdo_id ,rvdo_ment ,rvdo_date ,mem_id ,mem_name ,mem_image');
		$this->db->where('vdo_id' ,$vdo_id);
		$this->db->join('member','member.mem_id = rvdo_from','left');
		$query = $this->db->get('report_vdo');
		return $query->result_array();
	}



}